/**
 * Created by Shaobing on 24/05/2014.
 */
public class Isosceles {
    private final int _n;
    private final int _length;

    public Isosceles(int n) {
        _n = n;
        _length = n * 2 -1;
    }

    public StringBuilder drawLine(int lineNumber){
        int numberOfAsterisks = lineNumber * 2 + 1;
        int numberOfSpaces = (_length - numberOfAsterisks) / 2;

        StringBuilder stringBuilder = AppendSpaces(numberOfSpaces);
        AppendAsterisk(numberOfAsterisks, stringBuilder);

        return stringBuilder.append('\n');

    }

    private void AppendAsterisk(int numberOfAsterisks, StringBuilder stringBuilder) {
        for(int i = 0; i < numberOfAsterisks; i++){
            stringBuilder.append('*');
        }
    }

    private StringBuilder AppendSpaces(int numberOfSpaces) {
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0; i < numberOfSpaces; i++){
            stringBuilder.append(' ');
        }
        return stringBuilder;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < _n; i++) {
            stringBuilder.append(drawLine(i));
        }

        return stringBuilder.toString();
    }
}
